package com.ruoyi.city.service.impl;

import java.util.List;

import com.ruoyi.city.domain.SubwayStation;
import com.ruoyi.city.mapper.SubwayStationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.city.mapper.SubwayLineMapper;
import com.ruoyi.city.domain.SubwayLine;
import com.ruoyi.city.service.ISubwayLineService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 地铁线路Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-09-11
 */
@Service
public class SubwayLineServiceImpl implements ISubwayLineService 
{
    @Autowired
    private SubwayLineMapper subwayLineMapper;
    @Autowired
    private SubwayStationMapper subwayStationMapper;

    /**
     * 查询地铁线路
     * 
     * @param lineId 地铁线路主键
     * @return 地铁线路
     */
    @Override
    public SubwayLine selectSubwayLineByLineId(Integer lineId)
    {
//        subwayLineMapper.selectSubwayLineByLineId(lineId);
        SubwayLine subwayLine = subwayLineMapper.selectSubwayLineWayByLineId(lineId);
        System.out.println(subwayLine);
        return subwayLine;
    }

    /**
     * 查询地铁线路列表
     * 
     * @param subwayLine 地铁线路
     * @return 地铁线路
     */
    @Override
    public List<SubwayLine> selectSubwayLineList(SubwayLine subwayLine)
    {
        return subwayLineMapper.selectSubwayLineList(subwayLine);
    }

    /**
     * 新增地铁线路
     * 
     * @param subwayLine 地铁线路
     * @return 结果
     */
    @Override
    public int insertSubwayLine(SubwayLine subwayLine)
    {

        return subwayLineMapper.insertSubwayLine(subwayLine);
    }

    /**
     * 修改地铁线路
     * 
     * @param subwayLine 地铁线路
     * @return 结果
     */
    @Override
    @Transactional   //加一个事物，保证两个事物的原子性
    public int updateSubwayLine(SubwayLine subwayLine)
    {
        int lineResult = subwayLineMapper.updateSubwayLine(subwayLine);
        if(subwayLine.getStationName() != null || subwayLine.getLocation() != null){
            SubwayStation subwayStation = new SubwayStation();
            subwayStation.setLineId(subwayLine.getLineId());
            subwayStation.setStationName(subwayLine.getStationName());
            subwayStation.setLocation(subwayLine.getLocation());
            int stationResult =  subwayStationMapper.updateSubwayStation(subwayStation);
        }

        return lineResult;
    }

    /**
     * 批量删除地铁线路
     * 
     * @param lineIds 需要删除的地铁线路主键
     * @return 结果
     */
    @Override
    public int deleteSubwayLineByLineIds(Integer[] lineIds)
    {
        return subwayLineMapper.deleteSubwayLineByLineIds(lineIds);
    }

    /**
     * 删除地铁线路信息
     * 
     * @param lineId 地铁线路主键
     * @return 结果
     */
    @Override
    public int deleteSubwayLineByLineId(Integer lineId)
    {
        return subwayLineMapper.deleteSubwayLineByLineId(lineId);
    }
}
